package com.zzccyy.jpdemo.page

import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.zzccyy.jpdemo.R
import com.zzccyy.jpdemo.base.BasicBaseActivity
import com.zzccyy.jpdemo.bean.SearchListBean.DataBean.ListBean
import com.zzccyy.jpdemo.utils.ListAdapter3

class TrainInfoActivity : BasicBaseActivity(), View.OnClickListener {
    private var ivClose: ImageView? = null
    private var ttTilte: TextView? = null
    private var ttTime1: TextView? = null
    private var ttTime2: TextView? = null
    private var ttAdd1: TextView? = null
    private var ttAdd2: TextView? = null
    private var tttt: TextView? = null
    private var tttN: TextView? = null
    private var listAdapter3: ListAdapter3? = null

    override val layoutId: Int
        get() = R.layout.activity_train_info

    override fun findViews() {
        ivClose = findViewById(R.id.ivClose)
        ttTilte = findViewById(R.id.ttTilte)
        ttTime1 = findViewById(R.id.ttTime1)
        ttTime2 = findViewById(R.id.ttTime2)
        ttAdd1 = findViewById(R.id.ttAdd1)
        ttAdd2 = findViewById(R.id.ttAdd2)
        tttN = findViewById(R.id.tttN)
        tttt = findViewById(R.id.tttt)
        val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
        val linearLayoutManager = LinearLayoutManager(this)
        recyclerView.layoutManager = linearLayoutManager
        listAdapter3 = ListAdapter3(this@TrainInfoActivity, R.layout.item_sss)
        recyclerView.adapter = listAdapter3
    }

    override fun setListener() {
        ivClose!!.setOnClickListener(this)
    }


    override fun onClick(v: View) {
        super.onClick(v)
        when (v.id) {
            R.id.ivClose -> finish()
        }
    }


    override fun initData() {
        val bean = intent.getSerializableExtra("data") as ListBean?
        if (!TextUtils.isEmpty(bean!!.date)) {
            var date = ""
            if (bean.date!!.contains("-")) {
                val split =
                    bean.date!!.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
                if (split.size == 3) {
                    date = split[1] + "月" + split[2] + "日"
                }
            }
            ttTilte!!.text = date + "出发"
        }
        val ticketList = bean.ticketList
        listAdapter3!!.setNewData(ticketList)
        if (!TextUtils.isEmpty(bean.departuretime)) {
            ttTime1!!.text = bean.departuretime
        }
        if (!TextUtils.isEmpty(bean.arrivaltime)) {
            ttTime2!!.text = bean.arrivaltime
        }
        if (!TextUtils.isEmpty(bean.station)) {
            ttAdd1!!.text = bean.station
        }
        if (!TextUtils.isEmpty(bean.endstation)) {
            ttAdd2!!.text = bean.endstation
        }


        if (!TextUtils.isEmpty(bean.trainno)) {
            tttN!!.text = bean.trainno
        }
        if (!TextUtils.isEmpty(bean.costtime)) {
            tttt!!.text = bean.costtime
        }
    }
}